{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 02, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2> Basics of Python: Variables </h2>\n",
    "\n",
    "We review using variables in python here. \n",
    "\n",
    "Please run each cell and check the results.\n",
    "\n",
    "<b> Indention of codes <u>matters</u> in python!</b> \n",
    "\n",
    "In this notebook, each line of code should start from the left without any indention. Otherwise, you will get syntax error.\n",
    "\n",
    "Comments can be indented.\n",
    "\n",
    "The codes belonging to a conditional or loop statement or a function/procedure are indented. We will see them later."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This is a comment\n",
    "# A comment is used for explanations/descriptions/etc.\n",
    "# Comments do not affect the programs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's define an integer variable named a\n",
    "a = 5\n",
    "\n",
    "# let's print its value\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's define three integer variables named a, b, and c\n",
    "a = 2\n",
    "b = 4\n",
    "c = a + b # summation of a and b\n",
    "\n",
    "# let's print their values together \n",
    "print(a,b,c)\n",
    "# a single space will automatically appears in between"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's print their values in reverse order\n",
    "print(c,b,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's print their summation and multiplication\n",
    "print(a+b+c,a*b*c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's define variables with string/text values\n",
    "\n",
    "hw = \"hello world\" # we can use double quotes\n",
    "hqw = 'hello quantum world' # we can use single quotes\n",
    "\n",
    "# let's print them\n",
    "print(hw)\n",
    "print(hqw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's print them together by inserting another string in between\n",
    "print(hw,\"and\",hqw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's concatenate a few strings\n",
    "d = \"Hello \" + 'World' + \" but \" + 'Quantum' + \"World\" \n",
    "\n",
    "# let's print the result\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's print numeric and string values together\n",
    "print(\"a =\",a,\", b =\",b,\", a+b =\",a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's subtract two numbers\n",
    "d = a-b\n",
    "print(a,b,d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's divide two numbers\n",
    "d = a/b\n",
    "print(a,b,d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's divide two integers over integers\n",
    "# the result is always an integer with possible integer remainder\n",
    "d = 33 // 6\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# reminder/mod operator\n",
    "r = 33 % 6 \n",
    "# 33 mod 6 = 3\n",
    "# or when 33 is divided by 6 over integers, the reminder is 3\n",
    "# 33 = 5 * 6 + 3\n",
    "\n",
    "# let's print the result\n",
    "print(r) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Booleen variables\n",
    "t = True\n",
    "f = False\n",
    "\n",
    "# let's print their values\n",
    "print(t,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print their negations\n",
    "print(not t) \n",
    "print(\"the negation of\",t,\"is\",not t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(not f)\n",
    "print(\"the negation of\",f,\"is\",not f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define a float variable\n",
    "\n",
    "d = -3.4444\n",
    "\n",
    "# let's print its value and its square\n",
    "print(d, d * d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's use parathesis in our experessions.\n",
    "\n",
    "$(23 \\cdot 13)-(11 \\cdot 15) $\n",
    "\n",
    "Here $\\cdot$ represents the multiplication operator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "e = (23*13) - (11 * 15)\n",
    "print(e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's consider a more complex expression.\n",
    "\n",
    "$  -3 \\cdot (123- 34 \\cdot 11 ) + 4 \\cdot(5+ (23 \\cdot 15) ) $"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we can use more than one variable\n",
    "\n",
    "# left is the variable for the left part of the expression\n",
    "# we start with the multiplication inside the parathesis\n",
    "left = 34*11\n",
    "# we continue with the substruction inside the parathesis\n",
    "#     we reuse the variable named left\n",
    "left = 123 - left\n",
    "# we reuse left again for the multiplication with -3\n",
    "left = -3 * left\n",
    "\n",
    "# right is the variable for the right part of the expression\n",
    "# we use the same idea here\n",
    "right = 23 * 15\n",
    "right = 5 + right\n",
    "right = 4 * right\n",
    "\n",
    "# at the end, we use left for the result\n",
    "left = left + right\n",
    "\n",
    "# let's print the result\n",
    "print(left)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 1 </h3>\n",
    "\n",
    "Define three variables n1, n2, and n3, and set their values to 3 -4 6\n",
    "\n",
    "Define a new variable r1, and set its value to $ (2 \\cdot n1 + 3 \\cdot n2) \\cdot 2 - 5 \\cdot n3 $, where $\\cdot$ represents the multiplication operator. \n",
    "\n",
    "<i>The multiplication operator in python (and in many other programming languages) is *.</i>\n",
    "\n",
    "Then, print the value of r1. \n",
    "\n",
    "As you may also verify it by yourself that you should see -42 as the outcome."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# your solution is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B08_Python_Basics_Variables_Solutions.ipynb#task1\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 2 </h3>\n",
    "\n",
    "By using the same variables (you may not need to define them again), please print the following value\n",
    "$$\n",
    "    \\dfrac{(n1-n2)\\cdot(n2-n3)}{(n3-n1)\\cdot(n3+1)}\n",
    "$$\n",
    "\n",
    "You should see -3.3333333333333335 as the outcome"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# your solution is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B08_Python_Basics_Variables_Solutions.ipynb#task2\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 3 </h3>\n",
    "\n",
    "Define variables N and S, and set their values to your name and surname. \n",
    "\n",
    "Then, print the values of N and S with a prefix phrase \"hello from the quantum world to\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# your solution is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B08_Python_Basics_Variables_Solutions.ipynb#task3\">click for our solution</a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
